<?php use_helper('I18N') ?>

	<script>
	$(function() {
		$("#transferForm").validate({
            messages : {
                transactionPassword: {
                    remote: "<?php echo __('Transaction Password is not valid') ?>."
                }
            },
            rules : {
                "sponsorId" : {
                    required: true,
                    minlength : 8
                },
                "pinAmount" : {
                    required : true
                },
                "transactionPassword" : {
                    required : true,
                    remote: "/member/verifyTransactionPassword"
                }
            },
            submitHandler: function(form) {
                if (parseFloat($("#pinBalance").val()) < parseFloat($("#pinAmount").val())) {
					alert("In-sufficient Pin");
					return false;
				}
				
                form.submit();
            }
        });
        
		$("#sponsorId").change(function(){
        	if ($.trim($('#sponsorId').val()) != "") {
            	verifySponsorId();
            }
        });
        
        $("#pinAmount").numeric({
            decimal:false,
            minValue:0,
            maxValue:<?php echo $PinBalance; ?>
        });     
	});
	
	function verifySponsorId() {
    	$.ajax({
        	type : 'POST',
            url : "/member/verifySponsorId",
            dataType : 'json',
            cache: false,
            data: {
            	sponsorId : $('#sponsorId').val()
            },
                success : function(data) {
                    if (data == null || data == "") {
                        alert("Invalid Shareholder ID");
                        $('#sponsorId').focus();
                        $("#sponsorName").html("");
                    } else {
                        $("#sponsorName").html(data.nickname);
                    }
                },
                error : function(XMLHttpRequest, textStatus, errorThrown) {
                    alert("Your login attempt was not successful. Please try again.");
                }
            });
    }
	</script>

<form action="/member/transferPin" id="transferForm" method="post">
<table cellpadding="0" cellspacing="5" align="center" border="0">
    <tr>
        <td>
			<font color='white'><?php echo __('Shareholder ID'); ?></font>
		</td>
		<td>
			<input name="sponsorId" type="text" id="sponsorId" tabindex="1" maxlength="8" />
		</td>
    </tr>
    <tr>
        <td>
			<font color='white'><?php echo __('Shareholder Name'); ?></font>
		</td>
		<td>
			<font color='white'><span id="sponsorName"></span></font>
		</td>
    </tr>
    <tr>
        <td>
			<font color='white'><?php echo __('PIN Available'); ?></font>
		</td>
		<td>
			<input name="pinBalance" id="pinBalance" tabindex="2" disabled="disabled" value="<?php echo $PinBalance; ?>"/>
		</td>
    </tr>
    <tr>
        <td>
			<font color='white'><?php echo __('Transfer PIN Quantity'); ?></font>
		</td>
		<td>
			<input name="pinAmount" id="pinAmount" tabindex="3" />
		</td>
    </tr>
    <tr>
        <td>
			<font color='white'><?php echo __('Transaction Password'); ?></font>
		</td>
		<td>
			<input name="transactionPassword" type="password" id="transactionPassword" tabindex="4" />
		</td>
    </tr>
    <tr>
    	<td colspan=2 align='center'>
    	<?php if ($sf_flash->has('errorMsg')): ?>
			<span class="error-font"><?php echo $sf_flash->get('errorMsg') ?></span>
		<?php endif; ?>
		<?php if ($sf_flash->has('successMsg')): ?>
			<span class="font"><?php echo $sf_flash->get('successMsg') ?></span>
		<?php endif; ?>
    	</td>
    </tr>
    <tr>
        <td colspan=2 align='center'>
			<input type="submit" name="Button1" value="<?php echo __('Submit') ?>" language="javascript" id="btnTransfer" tabindex="5"/>
		</td>
    </tr>
</table>
</form>